#include <iostream>

using namespace std;
const int N=32;

int arr[2*N];
int dp[N*2][N*2];
int g[N*2][N*2];
void dfs(int left,int right)
{
	if(left>right)
		return;
	
	cout<<g[left][right]<<' ';
	
	dfs(left,g[left][right]-1);
	dfs(g[left][right]+1,right);
}
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>arr[i];
	}
	
	for(int len=1;len<=n;len++)
	{
		for(int i=1;i+len-1<=n;i++)
		{
			int j=i+len-1;
			
			for(int k=i;k<=j;k++)
			{
				int left= k==i?1:dp[i][k-1];
				int right= k==j?1:dp[k+1][j];
				
				int score=left*right+arr[k];
				if(i==j)
					score=arr[k];
				if(dp[i][j]<score)
				{
					dp[i][j]=score;
					g[i][j]=k;
				}
			}
		}
	}
	cout<<dp[1][n]<<endl;
	dfs(1,n);
	
	return 0;
}
